﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="topPanel">
    @Html.Partial("_OrganizeIdDDLToolbarSearchView")
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="btn_roles()"><i class="fa fa-pencil-square-o"></i>用户角色</a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="姓名/账户/工号" style="width: 180px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>

<script>
    $(function() {
        initControl();
        gridList();
    });

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/SystemManage/SysUser/GetPagintionGridJson",
            height: $(window).height() - 128,
            postData: { keyword: $("#txt_keyword").val(), OrganizeId: $("#OrganizeId").val() },
            colModel: [
               { label: '主键', name: 'Id', hidden: true },
               { label: "有效", name: "zt", width: 60, align: "left", formatter: function (cellvalue) { return cellvalue == "1" ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>"; } },
                { label: '账户', name: 'Account', width: 100, align: 'left' },
                { label: '工号', name: 'gh', width: 80, align: 'left' },
                { label: '姓名', name: 'Name', width: 100, align: 'left' },
                { label: 'OrganizeId', name: 'OrganizeId', hidden: true },
                {
                    label: '机构名称', name: 'OrganizeName', width: 120, align: 'left',
                },
                {
                    label: '科室名称', name: 'DepartmentName', width: 80, align: 'left',
                },
                {
                    label: "允许登录", name: "Locked", width: 100, align: "center",
                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue === true) {
                            return '<span class=\"label label-default\">停用</span>';
                        }
                        else {
                            return '<span class=\"label label-success\">正常</span>';
                        }
                    }
                }
            ],
            pager: "#gridPager",
            sortname: 'zt desc, Account',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val(), OrganizeId: $("#OrganizeId").val() },
                page: 1,
            }).trigger('reloadGrid');
        });
    }

    //回车事件
    $('#txt_keyword').keydownEnterEvent(function () {
        $('#btn_search').trigger('click');
    });

    function initControl() {

    }

    function btn_roles() {
        var seleRowid = jQuery("#gridList").jqGrid("getGridParam", "selrow");
        if (!(seleRowid)) {
            $.modalAlert("请选中一条信息", 'warning');
            return;
        }
        var thisOrgId = $("#gridList").jqGridRowValue().OrganizeId;
        if (!!!thisOrgId) {
            $.modalAlert("请先为用户关联人员", 'warning');
            return;
        }
        var keyValue = $("#gridList").jqGridRowValue().Id;
        $.modalOpen({
            id: "Form",
            title: "用户角色",
            url: "/SystemManage/SysUser/Roles?keyValue=" + keyValue + '&orgId=' + thisOrgId,
            width: "750px",
            height: "700px",
            callBack: function (iframeId) {
                $.currentWindow(iframeId).AcceptClick(function () {

                });
            }
        });
    }
    
</script>